﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WorldClock.BO;
using WorldClock.Converters;

namespace WorldClock.Test
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        public UnitTest1()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestMethod1()
        {
            WorldTimeViewModel worldTimeViewModel = new WorldTimeViewModel();
            Assert.IsTrue(worldTimeViewModel.TimeZoneInfoViewModels.Count > 0, "No timezone detected");
            HourToDegree converter = new HourToDegree();
            object o = converter.Convert(worldTimeViewModel.TimeZoneInfoViewModels[7].TotalMinutes, null, null, null);
        }

        [TestMethod]
        public void TransitionTimeConverter()
        {
            WorldTimeViewModel worldTimeViewModel = new WorldTimeViewModel();
            Assert.IsTrue(worldTimeViewModel.TimeZoneInfoViewModels.Count > 0, "No timezone detected");
            TimeZoneInfoViewModel tzivm = worldTimeViewModel.TimeZoneInfoViewModels[7]; //Paris time zone            
            /*System.TimeZoneInfo.TransitionTime tt1_start = System.TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 2, 0, 0), 3, 5, DayOfWeek.Sunday); 
            System.TimeZoneInfo.TransitionTime tt1_end = System.TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 3, 0, 0), 10, 5, DayOfWeek.Sunday);
            DateTime dt_start = tzivm.GetDateTimeFromTransitionTime(tt1_start);
            DateTime dt_end = tzivm.GetDateTimeFromTransitionTime(tt1_end);
            Assert.IsNotNull(dt_start);
            Assert.AreEqual(DateTime.Now.Year, dt_start.Year,"Mauvaise année");
            Assert.AreEqual(3, dt_start.Month, "Mauvais mois");
            Assert.AreEqual(29, dt_start.Day, "Mauvais jour");
            Assert.IsNotNull(dt_end);
            Assert.AreEqual(DateTime.Now.Year, dt_end.Year, "Mauvaise année");
            Assert.AreEqual(10, dt_end.Month, "Mauvais mois");
            Assert.AreEqual(25, dt_end.Day, "Mauvais jour");

            System.TimeZoneInfo.TransitionTime tt2_start = System.TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 2, 0, 0), 3, 3, DayOfWeek.Sunday);
            System.TimeZoneInfo.TransitionTime tt2_end = System.TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 3, 0, 0), 10, 2, DayOfWeek.Sunday);
            DateTime dt2_start = tzivm.GetDateTimeFromTransitionTime(tt2_start);
            DateTime dt2_end = tzivm.GetDateTimeFromTransitionTime(tt2_end);
            Assert.IsNotNull(dt2_start);
            Assert.AreEqual(DateTime.Now.Year, dt2_start.Year, "Mauvaise année");
            Assert.AreEqual(3, dt2_start.Month, "Mauvais mois");
            Assert.AreEqual(15, dt2_start.Day, "Mauvais jour");
            Assert.IsNotNull(dt2_end);
            Assert.AreEqual(DateTime.Now.Year, dt2_end.Year, "Mauvaise année");
            Assert.AreEqual(10, dt2_end.Month, "Mauvais mois");
            Assert.AreEqual(11, dt2_end.Day, "Mauvais jour");*/
            System.TimeZoneInfo.TransitionTime tt3_start = System.TimeZoneInfo.TransitionTime.CreateFixedDateRule(new DateTime(1, 1, 1, 3, 0, 0), 3, 2);
            System.TimeZoneInfo.TransitionTime tt3_end = System.TimeZoneInfo.TransitionTime.CreateFixedDateRule(new DateTime(1, 1, 1, 3, 0, 0), 4, 12);

            DateTime dt3_start = tzivm.GetDateTimeFromTransitionTime(tt3_start);
            DateTime dt3_end = tzivm.GetDateTimeFromTransitionTime(tt3_end);
            Assert.IsNotNull(dt3_start);
            Assert.AreEqual(DateTime.Now.Year, dt3_start.Year, "Mauvaise année");
            Assert.AreEqual(3, dt3_start.Month, "Mauvais mois");
            Assert.AreEqual(2, dt3_start.Day, "Mauvais jour");
            Assert.IsNotNull(dt3_end);
            Assert.AreEqual(DateTime.Now.Year, dt3_end.Year, "Mauvaise année");
            Assert.AreEqual(4, dt3_end.Month, "Mauvais mois");
            Assert.AreEqual(12, dt3_end.Day, "Mauvais jour");
        }
    }
}
